package main

import (
	"modules"
	"config"
	"os/signal"
	"os"
	"log"
	"betfc"
	"time"
)

func main() {
	loginTwo()
}

func loginOne() {
	//配置解析
	_, err := config.ParseConfigFile("/config.yaml")
	if err != nil {
		panic("解析配置失败")
	}
	loginKeep := new(modules.LoginKeep)
	loginKeep.OpenIndex()
	_, err = loginKeep.Search()
	loginKeep.GetLoginPage()
	//loginKeep.GetCode()
	base64img, err := loginKeep.GetCode()
	verCode, err := loginKeep.CheckCode(base64img)
	loginKeep.Login(verCode)

	//loginKeep.Login("1235")
}

func loginTwo() {
	////配置解析
	//config, err := config.ParseConfigFile("/config2.yaml")
	//if err != nil {
	//	panic("解析配置失败")
	//}
	//loginAuth := new(modules.LoginAuth)
	//loginAuth.InitConfig(config) //初始化配置
	//loginAuth.StartChrome()      //启动浏览器
	////loginAuth.Search()           //搜索码搜索
	//loginAuth.Index() //过验证码

	var tasks = [...]modules.IModule{
		new(modules.AuthTask),
	}

	for i := 0; i < len(tasks); i++ {
		modules.Register(tasks[i])
	}

	err := modules.Init()

	if err != nil {
		panic("启用错误:" + err.Error())
	}
	ch := make(chan os.Signal)

	signal.Notify(ch, os.Interrupt, os.Kill)
	WriteData()
	sig := <-ch
	log.Printf("server closed by signal %v", sig)
	modules.Destroy()

}

func WriteData() {
	time.Sleep(8e9)
	go betfc.GetKlcBetMap()
	go betfc.GetSccBetMap()
	go betfc.GetPkBetMap()
	go betfc.GetNcBetMap()
	go betfc.GetKbBetMap()
}
